<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/6/1
 * Time: 14:20
 */
namespace app\admin\controller;

use app\admin\model\ShopModel;
use app\admin\model\ShopTypeModel;

class Shop extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->shop = new ShopModel();
        $this->shoptype = new ShopTypeModel();
    }
    /**
     * 现有店铺
     */
    public function index()
    {
        $list = $this->shop->index();
        $shoptype = $this->shoptype->select();
        foreach ($list as $key=>$value)
        {
            foreach ($shoptype as $k=>$val)
            {
                if($value['type']==$val['id'])
                {
                    $list[$key]['type']=$val['name'];
                }
            }
        }
        $page = $list->render();
        $count = count($list);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('count',$count);
        return view('shop/index');
    }
    /**
     * 店铺编辑
     */
    public function edit()
    {
        if(request()->isAjax())
        {
            $res = $this->shop->edit();
            if($res)
            {
                return ['code'=>'1','message'=>'修改成功'];
            }else{
                return ['code'=>'0','message'=>'修改失败'];
            }
        }
        $id = input('id');
        $data = $this->shop->getOneId($id);
        $shoptype = $this->shoptype->select();
        $this->assign('data',$data);
        $this->assign('shoptype',$shoptype);
        return view('shop/edit');
    }
    public function del()
    {
        $res = $this->shop->del();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
    public function dell()
    {
        $res = $this->shop->dell();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
    /**
     * 店铺审核
    */
    public function examine()
    {
        $list = $this->shop->examine();
        $shoptype = $this->shoptype->select();
        foreach ($list as $key=>$value)
        {
            foreach ($shoptype as $k=>$val)
            {
                if($value['type']==$val['id'])
                {
                    $list[$key]['type']=$val['name'];
                }
            }
        }
        $page = $list->render();
        $count = count($list);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('count',$count);
        return view('shop/examine');
    }
    /**
     * 店铺申请同意
     */
    public function status()
    {
        $res = $this->shop->status();
        if($res)
        {
            return ['code'=>'1','message'=>'操作成功'];
        }else{
            return ['code'=>'0','message'=>'操作失败'];
        }
    }
    /**
     * 店铺申请同意
     */
    public function no_status()
    {
        $res = $this->shop->no_status();
        if($res)
        {
            return ['code'=>'1','message'=>'操作成功'];
        }else{
            return ['code'=>'0','message'=>'操作失败'];
        }
    }
}